package com.mindata.blockchain.socket.handler.server;

import com.mindata.blockchain.ApplicationContextProvider;
import com.mindata.blockchain.socket.base.AbstractBlockHandler;
import com.mindata.blockchain.socket.body.base.InstructionsBody;
import com.mindata.blockchain.socket.packet.BlockPacket;
import com.mindata.blockchain.socket.common.msg.InstructionMsg;
import com.mindata.blockchain.socket.common.queue.base.MsgQueueManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;

public class InstructionsHandler extends AbstractBlockHandler<InstructionsBody> {
    @Override
    public Class<InstructionsBody> bodyClass() {
        return InstructionsBody.class;
    }

    private Logger logger = LoggerFactory.getLogger(InstructionsHandler.class);

    @Override
    public Object handler(BlockPacket packet, InstructionsBody bsBody, ChannelContext channelContext) throws Exception {

        InstructionMsg msg = bsBody.getInstructionMsg();
//        logger.warn("{}处理收到的转发交易:\\n{}", this, bsBody);
        ApplicationContextProvider.getBean(MsgQueueManager.class).pushMsg(msg);
        return null;
    }
}
